package cn.lidar.config;

import cn.lidar.interfaces.ProcessService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
        if (beanName.equals("process")) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true) {
                        File dir = new File("C:" + File.separator + "LidarData" + File.separator + "bin");
                        if (dir.exists() && dir.isDirectory()) {
                            ProcessService process = (ProcessService) bean;
                            process.process(dir.listFiles());
                        }
                        try {
                            Thread.sleep(60000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();
        }
        return bean;
    }
}
